﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EyFramework.ORM;

namespace HzybService
{
    public static class HzybConstants
    {
        public static readonly string HOSP_CODE = "H33010900813";
        public static readonly string HOSP_NAME = "杭州市萧山区第二人民医院";
        public static readonly string p_大项分隔符 = "^";
        public static readonly string p_明细分隔符 = "$";
        public static readonly string p_管道分隔符 = "|";
        public static readonly string SEQUENCE_HZYB_YYJYLSH = "SEQ_HZYB_YYJYLSH";
        public static readonly string SEQUENCE_HZYB_JZLSH = "SEQ_HZYB_JZLSH";
        private static string YEWUZQH = "";

        public enum EnumYiLiaoLb
        {
            普通门诊 = 11,
            药店购药 = 12,
            急救报销120 = 13,
            规定病种门诊 = 14,
            血透单病种门诊 = 15,
            腹透单病种门诊 = 16,
            普通住院 = 21,
            家庭病床 = 25,
            单病种住院 = 26,
            其他 = 91,
            体检 = 92,
        }

        /// <summary>
        /// 创建医院交易流水号
        /// 规则：时间(14)-医院编号(最大 20)-流水号(4)，之间用-分隔
        /// </summary>
        /// <returns></returns>
        public static string GetYiYuanJylsh()
        {
            return DbHelper.GetSysDate("YYYYMMDDHH24MISS") + "-" + HOSP_CODE + "-" + DbHelper.GetSequence(SEQUENCE_HZYB_YYJYLSH);
        }

        /// <summary>
        /// 获取就诊流水号
        /// </summary>
        /// <returns></returns>
        public static string GetJiuZhenLsh()
        {
            return DbHelper.GetSysDate("YYYYMMDD") + "-01-" +
                   DbHelper.GetSequence(SEQUENCE_HZYB_YYJYLSH).ToString().PadLeft(6, '0');
        }

        public static decimal StrToDecimal(string sValue, decimal defaltVal = 0)
        {
            if (string.IsNullOrEmpty(sValue))
            {
                return defaltVal;
            }
            else
            {
                return Convert.ToDecimal(sValue);
            }
        }

        /// <summary>
        /// 根据操作员工号获取操作员有效签到记录
        /// </summary>
        /// <param name="caoZuoYuanDm"></param>
        /// <returns></returns>
        public static string GetYeWuZqh(string caoZuoYuanDm)
        {
            if (string.IsNullOrEmpty(YEWUZQH))
            {
                string sql = "SELECT YWZQH FROM HZYTH_QDDZ@OLDHIS WHERE STAF_CDE='{0}' AND STATUS='1'";
                using (var dt = DbHelper.SelectTable(string.Format(sql, caoZuoYuanDm)))
                {
                    if (dt.Rows.Count > 0)
                    {
                        YEWUZQH = dt.Rows[0]["YWZQH"].ToString();
                    }
                }
            }
            if (string.IsNullOrEmpty(YEWUZQH))
            {
                throw new Exception("获取业务周期号失败，请联系管理员签到！");
            }
            return YEWUZQH;
        }
    }
}